package com.wangtao.firstapp.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.Toast;

import com.wangtao.firstapp.R;

import java.util.ArrayList;

/**
 * 选择你感兴趣的分类
 * Created by lanouhn on 16/9/19.
 */
public class ChooseInterestActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener {
    private ImageView iv_back_titlebar_chooseinterest;// 标题栏返回按钮
    private Button btn_finish;// 完成按钮
    private CheckBox cb_wyqn, cb_xsd, cb_dpk, cb_smahz;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chooseinterest);
        initView();
        initData();
        initEvent();
    }

    private void initView() {
        iv_back_titlebar_chooseinterest = (ImageView) findViewById(R.id.iv_back_titlebar_chooseinterest);// 标题栏返回按钮
        btn_finish = (Button) findViewById(R.id.btn_finish);// 完成按钮
        cb_wyqn = (CheckBox) findViewById(R.id.cb_wyqn);
        cb_xsd = (CheckBox) findViewById(R.id.cb_xsd);
        cb_dpk = (CheckBox) findViewById(R.id.cb_dpk);
        cb_smahz = (CheckBox) findViewById(R.id.cb_smahz);
    }

    private void initData() {

    }


    private void initEvent() {
        // 标题栏返回按钮
        iv_back_titlebar_chooseinterest.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        cb_wyqn.setOnCheckedChangeListener(this);
        cb_xsd.setOnCheckedChangeListener(this);
        cb_dpk.setOnCheckedChangeListener(this);
        cb_smahz.setOnCheckedChangeListener(this);


        // 完成按钮
        btn_finish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(ChooseInterestActivity.this, "提交成功", Toast.LENGTH_SHORT).show();
                finish();
            }
        });
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        boolean flag = cb_wyqn.isChecked() || cb_xsd.isChecked() || cb_dpk.isChecked() || cb_smahz.isChecked();
        if (flag) {
            btn_finish.setEnabled(true);
        } else {
            btn_finish.setEnabled(false);
        }
    }
}
